package com.cardlan.twoshowinonescreen;

import java.io.FileDescriptor;

/**
 * Created by huasheng on 19-7-9.
 */

public interface ICardOperator {


    public CardLanDevUtil getCardLanDevUtil();

    public int callReadOne2FiveSectorDataFromCard(char VerifyFlag, byte[] key_array, char
            mode, byte[] returnArray);

    /**
     * open buzzer
     */
    public void callOpenBuzzer();

    /**
     * close buzzer
     */
    public void callCloseBuzzer();

    /**
     * open RedLED
     */
    public void callOpenRedLED();

    /**
     * close RedLED
     */
    public void callCloseRedLED();

    /**
     * open GreenLED
     */
    public void callOpenGreenLED();

    /**
     * close GreenLED
     */
    public void callCloseGreenLED();

    /**
     * init the device.
     *
     * @return int if return value equal {@link DeviceCardConfig#INIT_DEVICE_STATUS_SUCCESS}, it
     * means init devcie success, else not.
     */
    public int callInitDev();

    /**
     * stop search card
     */
    public void callCardHalt();

    /**
     * card reset
     *
     * @param CardSn array for saving card serial number.
     * @return int if return value equal {@link DeviceCardConfig#CARD_RESET_STATUS_MONE_SUCCESS
     * } it means mifare1 card , else equal {@link DeviceCardConfig#CARD_RESET_STATUS_CPU_SUCCESS
     * } it means cpu card．
     */
    public int callCardReset(byte[] CardSn);

    /**
     * read data from mifare1 card
     *
     * @param SectorNo   　sector index
     * @param BlockNo    　area index
     * @param VerifyFlag verify flag.Suggest options(1)
     * @param key_array  　key byte array
     * @param mode       　key check mode. suggest options(0x0a(read)/0x0b(write)).
     * @return byte[] return byte array data
     */
    public byte[] callReadOneSectorDataFromCard(char SectorNo, char BlockNo, char
            VerifyFlag, byte[] key_array, char mode);

    /**
     * write data array into mifare1 card
     *
     * @param SectorArray 　write data source array
     * @param SectorNo    　sector index
     * @param BlockNo     　area index
     * @param VerifyFlag  　verify flag.Suggest options(1)
     * @param key_array   　key byte array
     * @param mode        　key check mode. suggest options(0x0a(read)/0x0b(write)).
     * @return int return status, if the value equal
     * {@link DeviceCardConfig#MONE_CARD_WRITE_SUCCESS_STATUS} , it
     * means write data success.
     */
    public int callWriteOneSertorDataToCard(byte[] SectorArray, char SectorNo, char
            BlockNo, char VerifyFlag, byte[] key_array, char mode);

    /**
     * open serial . if you want san qr code , you must call this method.
     *
     * @param path     　file path,suggest ('/dev/ttyAMA4')
     * @param baudrate 　115200
     * @param flags    　suggest value 0
     * @return FileDescriptor file desc
     */
    public FileDescriptor callSerialOpen(String path, int baudrate, int flags);

    /**
     * close serial
     */
    public void callSerialClose();

    /**
     * send cpu card cmd
     *
     * @param cmdArray     cmd byte array
     * @param receiveArray 　the array for saving result value
     * @return int status
     */
    public int callCpuSendCmd(byte[] cmdArray, byte[] receiveArray);

    ////////SPI

    /**
     * open spi
     *
     * @param path  spi path
     * @param flags flag
     * @return Object return spi obj
     */
    public Object callSPIOpen(String path, int flags);

    /**
     * close current SPI
     */
    public void callSPIClose();

    /**
     * send spi cmd
     *
     * @param cmdBytes cmd byte array
     * @return byte[] spi call back data
     */
    public byte[] callSPITransfer(byte[] cmdBytes);


    /**
     * DES card key , the key byte array is your data source, the data byte array is your key
     * byte array. this method only used for mifare1 card.
     *
     * @param keyArray  　source byte array
     * @param dataArray 　key byte array
     * @return byte[] return the des result array,the array length is
     * {@link DeviceCardConfig#DES_OUT_ARRAY_LENGTH}
     */
    public byte[] callDesCard(byte[] keyArray, byte[] dataArray);

    /**
     * method for des cpu card
     *
     * @param desType  encrypt / decrypt
     * @param desMode  　ECB,CBC model
     * @param srcBytes 　data source
     * @param outBytes 　the result array for saving des value, this array length must equal the data
     *                 source length,or bigger than it.
     * @param keyBytes 　the key byte array , (support  8,16,24 bits)
     * @return char　return the des status
     */
    public char callRunDes(char desType, char desMode, byte[] srcBytes, byte[]
            outBytes, byte[] keyBytes);

    /**
     * this method is used to calculation cpu card  mac .
     *
     * @param initIn   encrypt / decrypt, allow null
     * @param srcBytes data source
     * @param outBytes the result array for saving des value, this array length must equal
     *                 the data source length,or bigger than it.
     * @param keyBytes the key byte array , (support  8,16,24 bits)
     * @return char　return the des status
     */
    public char callMacAnyLength(byte[] initIn, byte[] srcBytes, byte[] outBytes, byte[] keyBytes);


    public int callWrite(byte[] data, int len);

    public FileDescriptor callOpen(String path, int baudrate, int flags);

    public void callClose();

    public int callJTBCardread(byte[] data);

    public int callJTBNormalCardConsume(int money);

    public int callJTBCardLock();

    public int callYLCardread(byte[] data);

    public int callYLCardConsume(int type,int money);

    public int callYLCardHandleChannle1(int money,byte[] data);

    public void callQPBOCCalcMac(byte[] macKey,byte[] inData,int inLen,byte[] outMAC);

    //---------------------------------------------------------------------------------------------
    public int callInitTuPsam(byte[] psamNum,byte[] psamKeyIndex);
    public int callPsamSendCommand(int psamIndex, byte[] cmdArray,int cmdLen,byte[] receiveArray);
    public int callResetNfcChipSet();
    public int callCardResetToCpuInterface(byte[] data);

}
